package yhb

import com.tcl.bigdata.yhb.knn.KDTree
import org.apache.spark.sql.SQLContext
import org.apache.spark.{SparkConf, SparkContext}

import scala.util.Random

/**
  * Created by root on 15-12-18.
  */
object RunAlgorithm {

  def main(args: Array[String]) {
    val conf = new SparkConf().setAppName("run-algorithm").setMaster("local")
    val sc = new SparkContext(conf)
    val sqlContext = new SQLContext(sc)
    import sqlContext.implicits._
    val num = 10
    val a1 = new Array[Double](num)
    val a2 = new Array[Double](num)
    val a3 = new Array[Double](num)
    val r = new Random()
    for(i <- a1.indices){
      a1(i) = r.nextDouble()
      a2(i) = r.nextDouble()
      a3(i) = r.nextDouble()
    }

    val testData = sc.parallelize(a1 zip a2).toDF()
//    val testData = sc.parallelize(a1 zip a2 zip a3).map(x=>(x._1._1,x._1._2,x._2)).toDF()
    val kdTree = new KDTree(testData,"kd_tree_leaf_node","kd_tree_node")
//    kdTree.saveKDTree()
    sc.stop()
  }
}
